/**
 * 订单相关API
 * 封装与订单相关的所有接口请求
 */

const request = require('../utils/request');

/**
 * 催单
 * @param {string|number} id - 订单id
 * @returns {Promise} - 返回请求Promise
 */
const reminderOrder = (id) => {
  return request.get(`/user/order/reminder/${id}`);
};

/**
 * 再来一单
 * @param {string|number} id - 订单id
 * @returns {Promise} - 返回请求Promise
 */
const repeatOrder = (id) => {
  return request.post(`/user/order/repetition/${id}`);
};

/**
 * 历史订单查询
 * @param {Object} params - 查询参数
 * @param {string|number} params.page - 页码
 * @param {string|number} params.pageSize - 每页记录数
 * @param {string|number} [params.status] - 订单状态（可选）
 * @returns {Promise} - 返回请求Promise
 */
const getHistoryOrders = (params) => {
  return request.get('/user/order/historyOrders', params);
};

/**
 * 取消订单
 * @param {string|number} id - 订单id
 * @returns {Promise} - 返回请求Promise
 */
const cancelOrder = (id) => {
  return request.put(`/user/order/cancel/${id}`);
};

/**
 * 查询订单详情
 * @param {string|number} id - 订单id
 * @returns {Promise} - 返回请求Promise
 */
const getOrderDetail = (id) => {
  return request.get(`/user/order/orderDetail/${id}`);
};

/**
 * 用户下单
 * @param {Object} orderData - 订单数据
 * @param {number} orderData.addressBookId - 地址簿id
 * @param {number} orderData.amount - 总金额
 * @param {number} orderData.deliveryStatus - 配送状态：1立即送出 0选择具体时间
 * @param {string} orderData.estimatedDeliveryTime - 预计送达时间
 * @param {number} orderData.packAmount - 打包费
 * @param {number} orderData.payMethod - 付款方式
 * @param {string} orderData.remark - 备注
 * @param {number} orderData.tablewareNumber - 餐具数量
 * @param {number} orderData.tablewareStatus - 餐具数量状态 1按餐量提供 0选择具体数量
 * @returns {Promise} - 返回请求Promise
 */
const submitOrder = (orderData) => {
  return request.post('/user/order/submit', orderData);
};

/**
 * 订单支付
 * @param {Object} paymentData - 支付数据
 * @param {string} paymentData.orderNumber - 订单号
 * @param {number} paymentData.payMethod - 支付方式
 * @returns {Promise} - 返回请求Promise
 */
const payOrder = (paymentData) => {
  return request.put('/user/order/payment', paymentData);
};

module.exports = {
  reminderOrder,
  repeatOrder,
  getHistoryOrders,
  cancelOrder,
  getOrderDetail,
  submitOrder,
  payOrder
};